package com.corner.presenter.imp;

import com.corner.model.cornerservice.domain.User;
import com.corner.model.cornerservice.helper.UserHelper;
import com.corner.presenter.IChangePasswordPresenter;
import com.corner.presenter.base.BasePresenter;
import com.corner.ui.view.IChangePasswordView;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;

/**
 * Created by Administrator on 2015/7/15，19.16.
 * 描述：
 */
public class ChangePasswordPresenter extends BasePresenter<IChangePasswordView> implements IChangePasswordPresenter {

    @Override
    public void changePassword(String oldPassword, String newPassword) {
        view.showLoading(true);
        UserHelper.changePassword(oldPassword, newPassword).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<User>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
                if (view != null) {
                    view.changePasswordError(e.getMessage());
                    view.showLoading(false);
                }
            }

            @Override
            public void onNext(User user) {
                if (view != null) {
                    view.changePasswordSucess();
                    view.showLoading(false);
                }
            }
        });
    }
}
